//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "server\fn_playerDisconnected.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

	// private ["_player_name","_player_id","_player_uid","_player_pos", "_player_list"];
	// _player_name = _this select 0;
	// _player_id = _this select 0;
	// _player_uid = _this select 0;
	// _player = "";
	// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected",_this];};

	// _player_list = d_player_store getVariable "player_positions";
	// if (isNil "_player_list") then {_player_list = []};
	// _indexer = [];
	// _names = [];
	// _positions =[];
	// _index = -1;
	// // TODO: Implement an alternative where we check all logged in players and look in picked up objects
	// //       If a player in picked up objects is not present in the logged in list, then all his stuff is dropped.
	// if (count _player_list > 2) then {
		// _indexer = _player_list select 0;
		// _positions = _player_list select 1;
		// _names = _player_list select 2;
		// _index = _names find _player_name;
		// if (_index >= 0) then {
			// _player = _indexer select _index;
		// };
		// diag_log Format["(%1)[%2]: %3: %4: %5, %6",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected","Player list",_index,_player];
	// };
	// _player_pos = [];
	// if (_player != "") then { _player_pos = getPosATL (missionNamespace getVariable _player); };
	// if (isNil "_player_pos") then {_player_pos =[]};
	// if (count _player_pos > 0) then { if (surfaceIsWater[(_player_pos select 0),(_player_pos select 1)]) then {_player_pos =[]}; };

	// If ((count _player_pos < 3) OR (Format["%1",_player_pos] == "[0,0,0]")) then {
		// // The player pos is not to be found anymore
		// // We need to take the last one the server had
		// if (_index >= 0) then {
			// _player_pos = _positions select _index;
			// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4: %5",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected","Found position", _player_pos];};
		// };
	// } else {
		// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4: %5",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected","Player position", _player_pos];};
	// };
	// If ((count _player_pos < 3) OR (Format["%1",_player_pos] == "[0,0,0]")) then {
		// // In case all attempts failed to find the player, we spawn everything at the base flag
		// _player_pos = getMarkerPos "base_spawn_1";
		// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4: %5",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected","Flag position", _player_pos];};
	// };

	// if (_player != "") then {
		// _player_objects = [];
		// _array_index = -1;
		// _forindex = 0;
		// _pickedup_objects = ["mission_pickedup_objects",[]] call XNetGetJIP;
		// if (count _pickedup_objects > 0) then {
			// {
				// diag_log Format["(%1)[%2]: %3: %4: %5",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected","     Objects",_x];
				// if ((_x select 0) == _player) exitWith {
					// _player_objects = _x select 1;
					// _array_index = _forindex;
				// };
				// _forindex = _forindex + 1;
			// } foreach _pickedup_objects;
		// };
	// };
	// diag_log Format["(%1)[%2]: %3: %4: %5",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected","Player Objects",_player_objects];
	// if (_array_index >= 0) then {
		// if (isNil "_player_objects") then {_player_objects = []};
		// If (count _player_objects > 0) then {
			// _forindex = 0;
			// [false,[format["marker_drop_disconnect_%1",_player], _player_pos, "ICON", "ColorRed", [0.7,0.7],Format["%1's Mission Objects",_player_name],0,"hd_warning","",1]] call XfMissionMarker;
			// {
				// _object_array = _x;
				// if (!isNil "_object_array") then {
					// _item_desc = _object_array select 0;
					// _obj_type = _object_array select 1;
					// _action = _object_array select 2;
					// _parameters = _object_array select 3;
					// _creation_pos = _player_pos findEmptyPosition [0,50,_obj_type];
					// if (count _creation_pos > 0) then {
						// _new_object = createVehicle [_obj_type,_creation_pos,[],1,"NONE"];
						// if (!isNull _new_object) then {
							// [_new_object,_action] call XfMissionSetAction;
							// [_new_object,_parameters] call XfMissionSetParameters;
							// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 - %5(%6)",diag_tickTime,"mission_functions.sqf","Registering the object",(str _new_object),_action,count _parameters];};
							// _new_object call XfMissionAddObject;
							// ["d_all_mobject",_new_object] call XNetCallEvent;
							// ["d_msg",[Format[localize "STR_TMF_DROPITEM",_player_name,_item_desc],"all",objNull,"hq"]] call XNetCallEvent;
							// player removeAction _action_id;
						// };
					// } else {
						// localize "STR_TMF_DROPITEMFAILED" call XfGlobalChat;
					// };
				// };
				// _player_objects set [_forindex, "xXxDELxXx"];
				// _forindex = _forindex + 1;
				// diag_log Format["(%1)[%2]: %3: %4: %5",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected","    Object ",_x];
			// } foreach _player_objects;
			// _player_objects = _player_objects - ["xXxDELxXx"];
		// };
		// // We update the array with the new player object list.
		// _pickedup_objects set [_array_index,[_player,_player_objects]];
		// ["mission_pickedup_objects",_pickedup_objects] call XNetSetJIP;
	// } else {
		// // The player has no object nothing to do
		// diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected","The player has no objects listed"];
	// };
	// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: Picked up objects:%4",diag_tickTime,"mission_functions.sqf","XfMissionPlayerDisconnected",(["mission_pickedup_objects",[]] call XNetGetJIP)];};


TRACE("End");
TMFPROFILERSTOP;